import axios from 'axios';
import type { RouteRecordNormalized } from 'vue-router';
import { UserState } from '@/store/modules/user/types';
import { ajaxService } from '@/utils/request';

const env = import.meta.env;
let baseURL = env.VITE_APP_BASE_URL;
let userURL = env.VITE_USER_BASE_URL;

export interface LoginData {
  mobile: string;
  password: string;
}
export interface InfoData {
  id: number;
}

export interface LoginRes {
  token: string;
}
// export function login(data: LoginData) {
//   return axios.post<LoginRes>('http://192.168.0.120:9001/user/login', data);
// }

// #VITE_APP_CUSTOM_TAOGE_URL="http://192.168.0.120:8081"
// #VITE_APP_CUSTOM_LIANGGE_URL="http://192.168.0.120"
// #VITE_APP_CUSTOM_HONGGE_URL="http://192.168.0.120:9001"

export function login(data: LoginData) {
  return ajaxService({
    url: '/master/user/login',
    method: 'post',
    data,
    noToken: true,
    baseURL,
  });
}

// 获取用户信息
export function getUserInfo(params: InfoData) {
  return ajaxService({
    url: '/basis/sys/menu/getBy/staffId',
    method: 'get',
    params,
    baseURL: userURL,
  });
}

export function logout() {
  return axios.post<LoginRes>('/api/user/logout');
}

// export function getUserInfo() {
//   return axios.post<UserState>('/api/user/info');
// }

export function getMenuList() {
  return axios.post<RouteRecordNormalized[]>('/api/user/menu');
}

// // 获取用户信息
export function DownloadElement(url: string) {
  return ajaxService({
    url,
    method: 'get',
    responseType: 'blob',
  });
}

export function updatePassword(data: LoginData) {
  return ajaxService({
    url: '/master/user/update/password',
    method: 'put',
    data,
    baseURL,
  });
}
